package cn.fz.ssedemo.controller;

import cn.fz.ssedemo.domain.dto.LoginDto;
import cn.fz.ssedemo.domain.po.AdminEntity;
import cn.fz.ssedemo.domain.vo.ResultVO;
import cn.fz.ssedemo.service.AdminService;
import cn.fz.ssedemo.utils.JwtUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@Tag(name = "用户登陆模块")
public class LoginController {
    private final AdminService adminService;
    @Operation(summary = "用户登陆接口")
    @PostMapping("/login")
    public ResultVO<String> login(@RequestBody LoginDto loginDto){
        AdminEntity adminEntity = adminService.login(loginDto.getUsername(),loginDto.getPassword());
        Map<String,Object> map = new HashMap<>();
        map.put("adminNo",adminEntity.getAdminNo());
        map.put("id",adminEntity.getAdminId());

        String token = JwtUtils.createToken(map);
        return ResultVO.success(token);
    }
}
